home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / initramfs-tools / scripts / lupin-helpers < prev    next >
Text File  |  2009-10-26  |  3KB  |  84 lines

  1. . /scripts/casper-helpers
  2.  
  3. is_supported_fs(){
  4.     [ -z "${1}" ] && return 1
  5.     case ${1} in
  6.         ext2|ext3|ext4|xfs|jfs|reiserfs|vfat|ntfs|iso9660)
  7.             return 0
  8.             ;;
  9.     esac
  10.     return 1
  11. }
  12.  
  13. wait_for_devs(){
  14.     if [ -e /dev/.initramfs/lupin-waited-for-devs ]; then
  15.         return
  16.     fi
  17.     [ "$quiet" != "y" ] && log_begin_msg "...waiting for devs..."
  18.     udevadm trigger --subsystem-match=block
  19.     udevadm settle
  20.     #TBD, modprobe on demand?
  21.     modprobe ext3
  22.     modprobe ext4
  23.     modprobe reiserfs
  24.     modprobe xfs
  25.     modprobe jfs
  26.     modprobe vfat
  27.     modprobe fuse
  28.     [ "$quiet" != "y" ] && log_end_msg "...devs loaded..."
  29.     touch /dev/.initramfs/lupin-waited-for-devs
  30. }
  31.  
  32. find_path()
  33. {
  34.     local path="${1}"
  35.     # must match find_path_cleanup
  36.     local default_mountpoint="${2:-/tmpmountpoint}"
  37.     local mountoptions="${3:-ro}"
  38.     local mountpoint=
  39.     local dev devname devfstype
  40.     local trial_number
  41.     FOUNDDEV=
  42.     FOUNDPATH=
  43.     [ -z "${path}" ] && return 1
  44.     wait_for_devs
  45.     mkdir -p "${default_mountpoint}"
  46.     for trial_number in 1 2 3; do
  47.         [ $trial_number -gt 1 ] && sleep 3
  48.         for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v /ram | grep -v /loop | grep -v /fd); do
  49.             for dev in $(subdevices "${sysblock}"); do
  50.                 devname=$(sys2dev "${dev}")
  51.                 devfstype="$(get_fstype ${devname})"
  52.                 if is_supported_fs "${devfstype}" ; then
  53.                                     #if device is already mounted, do not remount
  54.                     if grep -q "^${devname} " /proc/mounts; then
  55.                         mountpoint=$(grep "^${devname} " /proc/mounts|cut -d ' ' -f 2)
  56.                         unmount=false                
  57.                     else                
  58.                         mountpoint="${default_mountpoint}"                    
  59.                         try_mount "$devname" "$mountpoint" "$mountoptions" || return 1
  60.                         unmount=true                
  61.                     fi                
  62.                     if [ -e "${mountpoint}${path}" ]; then
  63.                         FOUNDDEV="${devname}"
  64.                         FOUNDPATH="${mountpoint}${path}"
  65.                         return 0
  66.                     fi
  67.                     [ "${unmount}" = "true" ] && umount ${mountpoint} 2> /dev/null || true
  68.                 fi
  69.             done
  70.         done
  71.     done
  72.     return 1
  73. }
  74.  
  75. find_path_cleanup()
  76. {
  77.     # must match find_path
  78.     local default_mountpoint="${1:-/tmpmountpoint}"
  79.     if grep -q "^[^ ]* $default_mountpoint " /proc/mounts; then
  80.         umount "$default_mountpoint" 2>/dev/null || true
  81.     fi
  82.     rmdir "$default_mountpoint" 2>/dev/null || true
  83. }
  84.